import { REWARD_TYPE, type RewardPoolConfig, type RewardConfig } from './type';

/**
 * 通用奖励池配置
 */
export class RewardPoolPresets {
  /**
   * 创建怪物掉落池
   */
  static createMonsterDropPool(
    expAmount: number,
    spiritStoneQuantity: number,
    commonDrops: Array<{ itemId: string; quantity: number; rate: number }> = [],
    rareDrops: Array<{ itemId: string; quantity: number; rate: number }> = []
  ): RewardPoolConfig {
    const rewards: RewardConfig[] = [
      // 经验值奖励（必掉）
      {
        type: REWARD_TYPE.EXP,
        amount: expAmount,
        guaranteed: true,
      },
      // 灵石奖励
      {
        type: REWARD_TYPE.SPIRIT_STONE,
        quantity: spiritStoneQuantity,
        rate: 0.5,
      },
      // 普通掉落
      ...commonDrops.map((drop) => ({
        type: REWARD_TYPE.ITEM,
        itemId: drop.itemId,
        quantity: drop.quantity,
        rate: drop.rate,
      })),
      // 稀有掉落
      ...rareDrops.map((drop) => ({
        type: REWARD_TYPE.ITEM,
        itemId: drop.itemId,
        quantity: drop.quantity,
        rate: drop.rate,
      })),
    ];

    return {
      rewards,
      dropStrategy: 'probability',
      dropCount: 1,
    };
  }

  /**
   * 创建宝箱掉落池
   */
  static createChestDropPool(
    guaranteedDrops: Array<{ itemId: string; quantity: number }>,
    randomDrops: Array<{ itemId: string; quantity: number; weight: number }>,
    dropCount: number = 1
  ): RewardPoolConfig {
    const rewards: RewardConfig[] = [
      // 必掉物品
      ...guaranteedDrops.map((drop) => ({
        type: REWARD_TYPE.ITEM,
        itemId: drop.itemId,
        quantity: drop.quantity,
        guaranteed: true,
      })),
      // 随机掉落物品
      ...randomDrops.map((drop) => ({
        type: REWARD_TYPE.ITEM,
        itemId: drop.itemId,
        quantity: drop.quantity,
        weight: drop.weight,
      })),
    ];

    return {
      rewards,
      dropStrategy: 'weighted',
      dropCount,
    };
  }

  /**
   * 创建任务奖励池
   */
  static createQuestRewardPool(
    expAmount: number,
    fixedRewards: Array<{ itemId: string; quantity: number }>,
    choiceRewards: Array<{ itemId: string; quantity: number }> = [],
    choices: number = 1
  ): RewardPoolConfig {
    const rewards: RewardConfig[] = [
      // 固定经验奖励
      {
        type: REWARD_TYPE.EXP,
        amount: expAmount,
        guaranteed: true,
      },
      // 固定物品奖励
      ...fixedRewards.map((reward) => ({
        type: REWARD_TYPE.ITEM,
        itemId: reward.itemId,
        quantity: reward.quantity,
        guaranteed: true,
      })),
      // 可选物品奖励
      ...choiceRewards.map((reward) => ({
        type: REWARD_TYPE.ITEM,
        itemId: reward.itemId,
        quantity: reward.quantity,
      })),
    ];

    return {
      rewards,
      dropStrategy: 'fixed',
      dropCount: choices,
    };
  }

  /**
   * 创建商店商品池
   */
  static createShopItemPool(
    items: Array<{ itemId: string; price: number; stock?: number }>
  ): RewardConfig[] {
    return items.map((item) => ({
      type: REWARD_TYPE.ITEM,
      itemId: item.itemId,
      quantity: 1,
      // 这里可以扩展商店相关属性
    }));
  }
}
